home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / basic / mildred / mildred.lha / lha / ILBMviewer.lha / Display.ascii < prev    next >
Text File  |  1999-03-07  |  6KB  |  160 lines

  1.  
  2. ;Display
  3.  
  4. Statement Permit{}
  5. ;Permit multitasking, only if it is globally intended
  6.   SHARED Multitasking.b
  7.   If Multitasking Then Permit_
  8. End Statement
  9.  
  10. Statement Forbid{}
  11. ;Disable multitasking, if it isn't globally intended
  12.   SHARED Multitasking.b
  13.   If Multitasking Then Forbid_
  14. End Statement
  15.  
  16. Statement Multitasking{State.b}
  17. ;Toggle global multitasking on or off.
  18.   SHARED Multitasking.b
  19.   If State
  20.     If Multitasking=False Then Permit_
  21.   Else
  22.     If Multitasking Then Forbid_
  23.   EndIf
  24.   Multitasking=State
  25. End Statement
  26.  
  27. Function.b InitDisplay{Title$}
  28. ;Creates a display
  29. ;Title$=The screen title (not displayed)
  30.   SHARED PrefDisplayHeight.w,PrefDisplayID.l,PrefDisplayBuffering.b,*ScrVP._ViewPort,IsAGA.b
  31.   SHARED ChunkyBase.l,ChunkyBuffer.l,PrefDisplayLeft.w,PrefDisplayTop.w
  32.   SHARED PrefDisplayDepth.w,PrefDisplayWidth.w,DisplaySplit.w,CPUminimum.b
  33.   SHARED PlanarBuf(),ILBMHAM.l
  34.   ;Open a test screen first to a) test for AGA or GFX-Card, and b) because the dimensions might be
  35.   ;too large to open a chipram screen, and the dimensions for AGA have not yet been reduced to within limits
  36.   Dim ScrTags.TagItem(13)
  37.   Rect.Rectangle\MinX=0,0,320,240 ; For test
  38.   ScrTags(0)\ti_Tag=#SA_Width,320 ; For test
  39.   ScrTags(1)\ti_Tag=#SA_Height,240; For test
  40.   ScrTags(2)\ti_Tag=#SA_Depth,PrefDisplayDepth
  41.   ScrTags(3)\ti_Tag=#SA_DisplayID,PrefDisplayID
  42.   ScrTags(4)\ti_Tag=#SA_Type,$F
  43.   ScrTags(5)\ti_Tag=#SA_Quiet,True
  44.   ScrTags(6)\ti_Tag=#SA_ShowTitle,False
  45.   ScrTags(7)\ti_Tag=#SA_Behind,True
  46.   ScrTags(8)\ti_Tag=#SA_DClip,&Rect ; For test
  47.   ScrTags(9)\ti_Tag=#SA_Exclusive,True
  48.   ScrTags(10)\ti_Tag=#SA_Draggable,False
  49.   ScrTags(11)\ti_Tag=#SA_AutoScroll,True
  50.   ScrTags(12)\ti_Tag=#TAG_DONE,0
  51.   ScrTags(13)\ti_Tag=#TAG_DONE,0
  52.   UsedChip.l=(320 LSR 3)*PrefDisplayDepth*240 ; With test params
  53.   FreeChip.l=AvailMem_(#MEMF_CHIP)
  54.   Forbid{}
  55.   If ScreenTags(0,Title$,&ScrTags(0))<>0 ; Test for GFX-Card or AGA
  56.     NowChip.l=AvailMem_(#MEMF_CHIP)
  57.     Permit{}
  58.     If FreeChip-NowChip<UsedChip
  59.       ; Graphics card screen
  60.       IsAGA=False
  61.       PrefDisplayWidth AND $FFE0 ; For gfx-cards, width to nearest 32
  62.       ScrTags(0)\ti_Tag=#SA_Width,PrefDisplayWidth
  63.       Rect.Rectangle\MinX=0,0,PrefDisplayWidth,PrefDisplayHeight
  64.       ScrTags(1)\ti_Tag=#SA_Height,PrefDisplayHeight*PrefDisplayBuffering
  65.       ScrTags(8)\ti_Tag=#SA_DClip,&Rect
  66.       VWait 25 ; seems to be necessary (safer)
  67.       Free Screen 0
  68.       VWait 10 ; just to be on the safe side
  69.       If ScreenTags(0,Title$,&ScrTags(0))<>0
  70.         For Loop.w=0 To PrefDisplayBuffering-1
  71.           If Loop=0 Then WFlags.l=$1900 Else WFlags.l=$800
  72. If Window(Loop,0,PrefDisplayHeight*Loop,PrefDisplayWidth,PrefDisplayHeight,WFlags,"",0,0)=0 Then Function Return False
  73.           Menus Off
  74.           ScreensBitMap 0,Loop
  75.           *TmpBmp.bitmap=Addr BitMap(Loop)
  76.           Offset.l=*TmpBmp\_ebwidth*(PrefDisplayHeight*Loop)
  77.           For DLoop.w=0 To PrefDisplayDepth-1
  78.             *TmpBmp\_data[DLoop]=*TmpBmp\_data[DLoop]+Offset
  79.           Next DLoop
  80.         Next Loop
  81.       Else
  82.         Function Return False
  83.       EndIf
  84.     Else
  85.       ; AGA screen
  86.       IsAGA=True
  87.       PrefDisplayWidth AND $FFC0 ; For AGA, width to nearest 64
  88.       ScrTags(0)\ti_Tag=#SA_Width,PrefDisplayWidth
  89.       Rect.Rectangle\MinX=0,0,PrefDisplayWidth,PrefDisplayHeight
  90.       ScrTags(1)\ti_Tag=#SA_Height,PrefDisplayHeight ; Seperate buffers
  91.       ScrTags(8)\ti_Tag=#SA_DClip,&Rect
  92.       ScrTags(3)\ti_Tag=#SA_DisplayID,PrefDisplayID OR ILBMHAM
  93.       Forbid{}
  94.       VWait 25 ; seems to be necessary (safer)
  95.       Free Screen 0
  96.       For Loop.w=0 To PrefDisplayBuffering-1
  97.         If Loop=0 Then WFlags.l=$1900 Else WFlags.l=$800
  98.         If AvailMem_(#MEMF_CHIP)>=(PrefDisplayWidth*PrefDisplayHeight)+16
  99.           Memory.l=AllocMem((PrefDisplayWidth*PrefDisplayHeight)+16,$10002) ; Chip bitmap
  100.           Memory=(Memory+16) AND $FFFFFFF0 ; Align for move16's
  101.           If Memory<>0
  102.             CludgeBitMap Loop,PrefDisplayWidth,PrefDisplayHeight,PrefDisplayDepth,Memory
  103.             If Loop=0
  104.               ScrTags(12)\ti_Tag=#SA_BitMap,Addr BitMap(0)
  105.               If ScreenTags(0,Title$,&ScrTags(0))=0
  106.                 Permit{}
  107.                 Function Return False
  108.               EndIf
  109.             EndIf
  110.             If Window(Loop,0,0,PrefDisplayWidth,PrefDisplayHeight,WFlags,"",0,0)=0 Then Function Return False
  111.             Menus Off
  112.           Else
  113.             Permit{}
  114.             Function Return False
  115.           EndIf
  116.         Else
  117.           Permit{}
  118.           Function Return False
  119.         EndIf
  120.         PlanarBuf(Loop)=Memory
  121.       Next Loop
  122.       Permit{}
  123.       ;AGA centering only (may not work on gfx card, or be necessary)
  124.       DEFTYPE.DimensionInfo DimInfoBuf
  125.       GetDisplayInfoData_ FindDisplayInfo_(PrefDisplayID) AND $FFFFFFFF,&DimInfoBuf,SizeOf.DimensionInfo,#DTAG_DIMS,0
  126.       PrefDisplayLeft.w=((DimInfoBuf\TxtOScan\MaxX)-PrefDisplayWidth)/2
  127.       PrefDisplayTop.w=((DimInfoBuf\TxtOScan\MaxY)-PrefDisplayHeight)/2
  128.     EndIf
  129.     DisplaySplit.w=((PrefDisplayWidth/4)*3) AND $FFF0 ; Horizontal coord at which splitscreen starts (mult of 16)
  130.     *Scr._Screen=NPeekL(Addr Screen(0))
  131.     *ScrVP=ViewPort(0)
  132.     *ScrVP\DxOffset=PrefDisplayLeft,PrefDisplayTop
  133.     ScrollVPort_ *ScrVP
  134.     RethinkDisplay_
  135.     Use Palette 0
  136.     Menus Off
  137.     If *ScrVP\DHeight<>PrefDisplayHeight
  138.       Forbid{}
  139.       *Scr\Height=PrefDisplayHeight ; Enforce y clipping
  140.       Permit{}
  141.     EndIf
  142.     ScreenToFront_ *Scr
  143.     ; Make chunky buffer
  144.     NowFast.l=AvailMem_(#MEMF_FAST)
  145.     If NowFast<PrefDisplayWidth*(PrefDisplayHeight+#ChunkyClipTop+#ChunkyClipBottom)+16 Then Function Return False
  146.     ChunkyBase.l=AllocMem(PrefDisplayWidth*(PrefDisplayHeight+#ChunkyClipTop+#ChunkyClipBottom)+16,$10000)
  147.     If ChunkyBase=0 Then Function Return False
  148.     ChunkyBase=(ChunkyBase+16) AND $FFFFFFF0 ; Align for move16's
  149.     ChunkyBuffer.l=ChunkyBase+(#ChunkyClipTop*PrefDisplayWidth)
  150.     If IsAGA
  151.       Mc2pWindow 0,PrefDisplayWidth,PrefDisplayHeight,PrefDisplayWidth,CPUminimum,PrefDisplayWidth,PrefDisplayHeight
  152.     EndIf
  153.     Function Return True
  154.   Else
  155.     Permit{}
  156.     Function Return False
  157.   EndIf
  158. End Function
  159.  
  160.